/**
 * Created by lixiaodi on 2018/11/5.
 */
mini.parse();
// mini_debugger = false;
var tree = mini.get("tree1");       //得到树
var grid = mini.get("datagrid1");   //得到表

//树结构显示
function http(){
   $.ajax({
       url: ajaxUrl + "/formltems/formTree.do?formListId=29",
       type:"post",

       success:function (data) {
           console.log(data);
           $.ajax({
               url: ajaxUrl + "/formList/findByFormListId.do?formListId=29"  ,
                type: "post",
                dataType: "json",
               success:function(textFieldData) {
                   console.log(textFieldData);
                   textField = $.parseJSON(textFieldData.data).selecteds[0].cTableField;
                   console.log(textField,'树形textField');
                   tree.set({
                       textField: 'name'
                   });
                   tree.setData(data);
                   var clickNodeFlag = 0;
                   tree.on("nodeselect", function (e) {
                       console.log(e);
                       clickNodeFlag++;
                       treeSelected = e.selected;
                       nodes = tree.getAncestors(treeSelected);
                       nodes.push(treeSelected);
                       $.ajax({
                           url: ajaxUrl + "/formltems/selectArchives.do?formListId=29",
//                                url:"http://192.168.31.65:8080/bpm/formltems/selectArchives.do",
                           type: "post",
                           dataType: "json",
                           data: {

                               condition: e.node.tabName,
                               conValue: e.node.id
                           },
                           success: function(data){
                               console.log(data);
                               grid_data = data.data;
                               grid.setData(grid_data);
                           },
                           error : function(data){
                           }
                       });
                   })
               }
           })


         },
       error: function (data) {
                    mini.alert("失败");
                }
   })
//     $.ajax({
//         url: ajaxUrl + "/formltems/formTree.do?formListId=29",
//         type: "post",
//         success: function (data) {
//             tree.setData(data.data);
//             console.log(data, 'treeData');
//             $.ajax({
//                 url: ajaxUrl + "/formList/findByFormListId.do?formListId=" + formId,
//                 type: "post",
//                 dataType: "json",
//                 success: function (textFieldData) {
//                     textField = $.parseJSON(textFieldData.data).selecteds[0].cTableField;
// //                        condition = $.parseJSON(textFieldData.data).selecteds[0].cTableName;
//                     console.log(textField, '树形textField');
//                     tree.set({
//                         textField: 'name'
//                     });
// //                        tree.loadList(treeData, "id", "parent_level");
// //                        console.log(tree.getData());
//                     tree.setData(treeData);
//                     var clickNodeFlag = 0;
//                     tree.on("nodeselect", function (e) {
//                         console.log(e);
//                         clickNodeFlag++;
//                         treeSelected = e.selected;
//                         nodes = tree.getAncestors(treeSelected);
//                         nodes.push(treeSelected);
//                         $.ajax({
//                             url: ajaxUrl + "/formltems/selectArchives.do",
// //                                url:"http://192.168.31.65:8080/bpm/formltems/selectArchives.do",
//                             type: "post",
//                             dataType: "json",
//                             data: {
//                                 formListId: formId,
//                                 condition: e.node.tabName,
//                                 conValue: e.node.id
//                             },
//                             success: function (data) {
//                                 console.log(data);
//                                 grid_data = data.data;
//                                 grid.setData(grid_data);
//                             },
//                             error: function (data) {
//                             }
//                         });
//                     })
//                 },
//                 error: function (data) {
//                     mini.alert("失败");
//                 }
//             })
}
http();
//选择节点

// 确定
function onOk(){
	var row = grid.getSelected();
	console.log(row);
	userInfoData = row;
	return userInfoData;
}
// 取消
function onCancel(){
	console.log(window.parent.KisBpmAssignmentPopupCtrl);
}
//弹出
function alertBox() {
	mini.alert('请选择用户');
}